﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuaManSys.Common
{
    public class OuterRelatedDeptOperation
    {
        /// <summary>
        /// 讲质量编号为infoid涉及到的部门dept写入内部表中
        /// </summary>
        /// <param name="infoid"></param>
        /// <param name="dept"></param>
        public static void AddOuterRelatedDept(string infoid, string dept)
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                OuterRelatedDepts ird = new OuterRelatedDepts
                {
                    qualityInfoId = infoid,
                    relatedDept = dept
                };

                context.OuterRelatedDepts.Add(ird);
                context.SaveChanges();
            }
        }

        /// <summary>
        /// 查询质量编号为infoid的所有涉及的部门
        /// </summary>
        /// <param name="infoid"></param>
        /// <returns></returns>
        public static List<string> QueryOuterRelatedDept(string infoid)
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                var db = (from q in context.OuterRelatedDepts
                          where q.qualityInfoId.Equals(infoid)
                          select q).Distinct();
                List<string> ret = new List<string>();
                foreach (var item in db)
                {
                    ret.Add(item.relatedDept);
                }
                return ret;
            }
        }
    }
}